#include "encrypt.h"
#include "utils.h"
#include <stdio.h>
#include <stdlib.h>

int encrypt_file(const char *input_path, const char *output_path, CipherContext *ctx) {
    FILE *in = fopen(input_path, "rb");
    FILE *out = fopen(output_path, "wb");

    if (!in || !out) {
        fprintf(stderr, "Failed to open file\n");
        return -1;
    }

    int ch;
    size_t key_index = 0;
    while ((ch = fgetc(in)) != EOF) {
        fputc(ch ^ ctx->password[key_index % ctx->password_len], out);
        key_index++;
    }

    fclose(in);
    fclose(out);
    return 0;
}